/*
 * strcpy_s.c - Safe string copy with bounds checking
 */

#include "bounds_check.h"
#include "bounds_check_internal.h"
#include <string.h>

int strcpy_s(char *dest, size_t dest_size, const char *src) {
    if (!is_valid_buffer(dest, dest_size) || src == NULL) {
        return BOUNDS_CHECK_INVALID_PARAM;
    }

    size_t src_len = 0;
    while (src[src_len] != '\0') {
        src_len++;
        if (src_len >= dest_size) {
            /* Source string too long for destination */
            dest[0] = '\0';
            return BOUNDS_CHECK_BUFFER_TOO_SMALL;
        }
    }

    /* Copy including null terminator */
    for (size_t i = 0; i <= src_len; i++) {
        dest[i] = src[i];
    }

    return BOUNDS_CHECK_SUCCESS;
}